//消息通知列表
var express = require('express');
var router = express.Router();
const messageModel = require('../../model/messageModel')

// 用户模型
const uaerModel = require('../../model/uaerModel')


// 查询评论通知详情
router.post('/dynamic/list', async function (req, res, next) {
    await messageModel.find({ byUserId: req.body.userId, isDynamic: 0 }).sort({ date: -1 }).then((data) => {
        res.send({
            code: 200,
            success: true,
            msg: "评论消息查询成功",
            data,
        })
    }).catch((err) => {
        res.send({
            code: 500,
            success: false,
            msg: "评论消息查询失败",
            data: err
        })
    });
})

// 查询点赞通知详情
router.post('/give/list', async function (req, res, next) {
    await messageModel.find({ byUserId: req.body.userId, isGive: 0 }).sort({ date: -1 }).then((data) => {
        res.send({
            code: 200,
            success: true,
            msg: "点赞消息查询成功",
            data,
        })
    }).catch((err) => {
        res.send({
            code: 500,
            success: false,
            msg: "点赞消息查询失败",
            data: err
        })
    });
})

// 查看后删除消息
router.post('/delete', async function (req, res, next) {
    await messageModel.deleteOne({
        id: req.body.id
    }).then(data => {
        res.send({
            code: 200,
            msg: "已删除",
            success: true,
            data,
        })
    }).catch((err) => {
        res.send({
            code: 500,
            success: false,
            msg: "删除失败",
            data: err
        })
    });
})

module.exports = router;
